home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / xview / guidexv / gutil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-14  |  3.3 KB  |  121 lines

  1. /*
  2.  * This file is a product of Sun Microsystems, Inc. and is provided for
  3.  * unrestricted use provided that this legend is included on all tape
  4.  * media and as a part of the software program in whole or part.  Users
  5.  * may copy or modify this file without charge, but are not authorized to
  6.  * license or distribute it to anyone else except as part of a product
  7.  * or program developed by the user.
  8.  * 
  9.  * THIS FILE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  10.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  11.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  12.  * 
  13.  * This file is provided with no support and without any obligation on the
  14.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  15.  * modification or enhancement.
  16.  * 
  17.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  18.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS FILE
  19.  * OR ANY PART THEREOF.
  20.  * 
  21.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  22.  * or profits or other special, indirect and consequential damages, even
  23.  * if Sun has been advised of the possibility of such damages.
  24.  * 
  25.  * Sun Microsystems, Inc.
  26.  * 2550 Garcia Avenue
  27.  * Mountain View, California  94043
  28.  */
  29.  
  30. #ifndef lint
  31. static char    sccsid[] = "@(#)gutil.c    2.6 91/10/15 Copyright 1989 Sun Microsystems";
  32. #endif
  33.  
  34.  
  35. #include    <stdio.h>
  36. #include    <sys/param.h>
  37. #include    <sys/types.h>
  38. #include    <xview/xview.h>
  39. #include    <xview/panel.h>
  40.  
  41.  
  42. /*
  43.  * Returns TRUE if the given xview event is a double click
  44.  * event.
  45.  * The time and drag thresholds are initialized to the values
  46.  * specified in the .Xdefaults file.
  47.  */
  48. int
  49. #ifdef __STDC__
  50. doubleclick(Event *event)
  51. #else
  52. doubleclick(event)
  53.     Event    *event;
  54. #endif
  55. {
  56.     int            ret_value = FALSE;
  57.     struct    timeval        current_select_time;
  58.  
  59.     static    short        first_time = TRUE;
  60.     static    int        time_threshold;
  61.     static    int        drag_threshold;
  62.     static    struct timeval     last_select_time;
  63.     static     Rect        last_area;
  64.  
  65.     if (event_action(event) != ACTION_SELECT || !event_is_down(event))
  66.         return FALSE;
  67.  
  68.     /*
  69.      * Init the thresholds the first time this is called.
  70.      */
  71.     if( first_time )
  72.     {
  73.         time_threshold =
  74.             defaults_get_integer("openwindows.multiclicktimeout",
  75.                          "OpenWindows.MultiClickTimeout",
  76.                          4);
  77.  
  78.         /*
  79.          * Convert for timeval.tv_usec.
  80.          */
  81.         time_threshold *= 100000;
  82.                 
  83.         drag_threshold = 
  84.             defaults_get_integer("openwindows.dragthreshold",
  85.                          "OpenWindows.DragThreshold", 5);
  86.  
  87.         first_time    = FALSE;
  88.     }
  89.     
  90.     current_select_time = event_time(event);
  91.  
  92.     /* 
  93.      * Make sure we have not moved too far in between clicks.
  94.      */
  95.     if (rect_includespoint(&last_area, event_x(event), event_y(event)))
  96.     {
  97.         if (current_select_time.tv_sec == last_select_time.tv_sec)
  98.         {
  99.             /* Check if micro seconds are in range */
  100.             if ((current_select_time.tv_usec -
  101.                  last_select_time.tv_usec) < time_threshold)
  102.                 ret_value = TRUE;
  103.         }
  104.         else if (current_select_time.tv_sec ==
  105.              (last_select_time.tv_sec + 1))
  106.         {
  107.             /* Check for rollover condition. */
  108.             if ((1000000 - last_select_time.tv_usec +
  109.                  current_select_time.tv_usec) < time_threshold)
  110.                 ret_value = TRUE;
  111.             
  112.         }
  113.     }
  114.     last_select_time = current_select_time;
  115.     last_area.r_left = event_x(event) - drag_threshold;
  116.     last_area.r_top  = event_y(event) - drag_threshold;
  117.     last_area.r_width = last_area.r_height = 2 * drag_threshold;
  118.  
  119.     return ret_value;
  120. }
  121.